﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ElevatorLib
{
    /// <summary>
    /// 泊松分布
    /// </summary>
    public class PoissonDistr : IDistribution
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="rnd"></param>
        /// <param name="lambda"></param>
        public PoissonDistr(Random rnd, double lambda)
        {
            if (lambda <= 0.0)
            {
                lambda = 0;
                throw new Exception("Lambda must be greater than 0,0");
            }
            this.rnd = rnd;
            this.lambda = lambda;
        }

        #region Properties
        /// <summary>
        /// 随机数
        /// </summary>
        private Random rnd;
        /// <summary>
        /// 大于0
        /// </summary>
        private double lambda;
        #endregion

        #region IDistribution 成员

        /// <summary>
        /// 生成样本
        /// </summary>
        /// <returns></returns>
        public double Sample()
        {
            double value = -Math.Log(Math.E, rnd.NextDouble()) / lambda;
            return value;
        }

        #endregion
    }
}
